<template>
	<!-- 基本信息折叠面板 -->
	<view class="collapse" :style="{borderRadius: borderRadius + 'px'}">
		<view :class="['collapse_title', hasIcon ? 'has-icon' : '']" @click="isOpen = !isOpen">
			<view class="collapse_name">{{ name }}</view>
			<image src="@/static/synergy/arrow.png" mode=""
				:style="{transform: isOpen?'rotate(0deg)':'rotate(180deg)'}"></image>
		</view>
		<view :style="{ height: isOpen?'2rpx':'0' }" class="line"></view>
		<view class="collapse_content" id="collapse_main" :style="{ height: isOpen?maxHeight + 'px':0 }">
			<slot></slot>
		</view>
		<slot name="handler"></slot>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isOpen: true,
			}
		},
		props: {
			name: {
				type: String
			},
			maxHeight: {
				type: [Number, String],
				require: true
			},
			borderRadius: {
				default: 10
			},
			hasIcon: {
				default: false
			}
		},
		methods: {}
	}
</script>
<style lang="scss" scoped>
	.collapse {
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1000);
		// border-radius: 10px;
		margin-bottom: 20rpx;

		.collapse_title {
			// padding: 20rpx;
			padding: 16rpx 32rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.collapse_name {
				font-size: 14px;
				// font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #171717;
				line-height: 20px;
			}

			image {
				width: 16px;
				height: 16px;
				transition: transform .3s, -webkit-transform .3s;
			}
		}

		.has-icon {
			position: relative;
			.collapse_name {
				margin-left: 12rpx;
				font-size: 17px;
				font-weight: 500;
				color: #333333;
			}
		}

		.has-icon::after {
			position: absolute;
			content: "";
			width: 6rpx;
			height: 29rpx;
			background: #1E6FFF;
		}

		.line {
			width: 100%;
			background: rgba(0, 0, 0, 0.1);
			transition: height .3s;
		}

		.collapse_content {
			transition: height .4s ease-in-out, -webkit-transform .4s ease-in-out, transform .4s ease-in-out;
			transform-origin: 50% 50% 0px;
			overflow: hidden;
		}
	}
</style>